
{mfdeclre.i}

/* e-outcus.p - Export the Customer table to an xml file*/
DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hRoot1 AS HANDLE.
DEFINE VARIABLE hRoot2 AS HANDLE.
DEFINE VARIABLE hRow AS HANDLE.
DEFINE VARIABLE hField AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.
DEFINE VARIABLE hBuf AS HANDLE.
DEFINE VARIABLE hDBFld AS HANDLE.
DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE j AS INTEGER.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hRow.
CREATE X-NODEREF hField.
CREATE X-NODEREF hText.

DEFINE VARIABLE str AS CHARACTER.

/*set up a root node*/
hDoc:CREATE-NODE(hRoot,"Customers","ELEMENT").
hDoc:APPEND-CHILD(hRoot).

FOR EACH ad_mstr NO-LOCK WHERE ad_addr <= "CA012" AND ad_addr >= "CA004" :

    hDoc:CREATE-NODE(hRow,"Customer","ELEMENT"). /*create a row node*/

    hRoot:APPEND-CHILD(hRow). /*put the row in the tree*/

/*
    {gprunp.i "hkbase64" "p" "base64Encode" "(input ad_addr, output str)"}
*/    
    hRow:SET-ATTRIBUTE("CustNo",ad_addr).

    {gprunp.i "hkbase64" "p" "base64Encode" "(input ad_name, output str)"}
    hRow:SET-ATTRIBUTE("CustName",str).

    /*Add the other fields as tags in the xml*/
    hDoc:CREATE-NODE(hField, "ContactMan", "ELEMENT").
    hRow:APPEND-CHILD(hField).
    hDoc:CREATE-NODE(hText, "", "TEXT").
    hField:APPEND-CHILD(hText).
    {gprunp.i "hkbase64" "p" "base64Encode" "(input ad_attn, output str)"}
    hText:NODE-VALUE = str.

    hDoc:CREATE-NODE(hField, "Address", "ELEMENT").
    hRow:APPEND-CHILD(hField).
    hDoc:CREATE-NODE(hText, "", "TEXT").
    hField:APPEND-CHILD(hText).
    {gprunp.i "hkbase64" "p" "base64Encode" "(input ad_line1 + ad_line2 + ad_line3, output str)"}
    hText:NODE-VALUE = str .

END.

/*write the XML node tree to an xml file*/
hDoc:SAVE("file","f:\hk_src\xml\cust.xml").
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hRow.
DELETE OBJECT hField.
DELETE OBJECT hText.
